
package ch.unisi.inf.pfii.teamwhite.risk.core.player;

import java.util.ArrayList;

import junit.framework.TestCase;
import ch.unisi.inf.pfii.teamwhite.risk.core.Planet;

public class HumanTest extends TestCase {

	private ArrayList<Planet> planets;
	private ArrayList<Planet> neighbors;
	
	/**
	 * A test to see if the ships of the planet is increased once the method, AssignPlanets(planets)
	 * is finished running.
	 */	
	public void testAssignPlanets()
	{
		Human human = new Human("CiaoBetty");				
		planets = new ArrayList<Planet>();
        Planet selectedPlanet = new Planet("Earth", human, 2000);
		Planet planet2 = new Planet("Venus", human, 2000);
		
		human.setSelectedPlanet(selectedPlanet);
		human.assignPlanets(planets);
		
		assertFalse(selectedPlanet.getShips().size() == planet2.getShips().size());
	}

	/**
	 * A test to see if the building on the planet is a Tax Center once the method build(Building)
	 * is finished running.
	 */	
	public void testbuild()
	{
		Human human = new Human("CiaoBetty");
        Planet selectedPlanet = new Planet("Earth", human, 2000);
		
        human.setSelectedPlanet(selectedPlanet);
        String building = "Tax Center";
        
		human.build(building);
		assertTrue(selectedPlanet.getBuilding().getName() == building);
	}
	
	/**
	 * A test to see if the money on the planet is decreased once the method buyShip()
	 * is finished running.
	 */
	public void testBuyShip()
	{
		Human human = new Human("CiaoBetty");
        Planet selectedPlanet = new Planet("Earth", human, 2000);
		
        human.setSelectedPlanet(selectedPlanet);
		human.buyShip();		
		
		assertTrue(human.getMoney() == 500);
	}
	
	/**
	 * A test to see if the player is able all of his ship from his planet to his neighbor (Impossible)
	 */
	public void testMoveAllShips()
	{
		Human human = new Human("CiaoBetty");
        Planet selectedPlanet = new Planet("Earth", human, 2000);
        // Create 5 ships in the selectedPlanet
        for (int i = 1; i <= 5; i++) {
			selectedPlanet.createShip();
		}
        
        Planet subPlanet2 = new Planet("Venus", human, 2000);
        neighbors = new ArrayList<Planet>(); 
        neighbors.add(subPlanet2);
        selectedPlanet.setNeighbours(neighbors);
        
        // testing if all but one ship gets transfered to Planet Venus
        human.setSelectedPlanet(selectedPlanet); 
        String destinationPlanet = "Venus"; 
        int shipsToMove = 5;
        human.moveShips(destinationPlanet, shipsToMove);
        assertEquals(true, subPlanet2.getShips().size() == 0);       
	}		
	
	/**
	 * A test to see if the player is able to move at least one less than all his ships
	 * from his planet to his neighbor (Possible)
	 */
	public void testMoveSomeShips()
	{
		Human human = new Human("CiaoBetty");
        Planet selectedPlanet = new Planet("Earth", human, 2000);
        // Create 5 ships in the selectedPlanet
        for (int i = 1; i <= 5; i++) {
			selectedPlanet.createShip();
		}
        
        Planet subPlanet3 = new Planet("Mars", human, 2000);
        neighbors = new ArrayList<Planet>();
        neighbors.add(subPlanet3);
        selectedPlanet.setNeighbours(neighbors);
        
        // testing if all but one ship gets transfered to Planet Venus
        human.setSelectedPlanet(selectedPlanet); 
        String destinationPlanet = "Mars"; 
        int shipsToMove = 2;
        human.moveShips(destinationPlanet, shipsToMove);
        assertEquals(true, subPlanet3.getShips().size() == 2);       
	}
	
	/**
	 * A test to see if the Owner, CiaoBetty, conquers the planet.
	 */
	public void testConquer()
	{
		Human human = new Human("CiaoBetty");
		Planet planet = new Planet("Jupiter", human, 2000);
		human.conquerPlanet(planet);
		assertTrue(planet.getOwner().getName() == "CiaoBetty");
	}
	
	/**
	 * A test to see if one of the planets from the available list of planets is selected. 
	 */
	public void testSelectPlanet()
	{
		Human human = new Human("CiaoBetty");
        Planet selectedPlanet = new Planet("Earth", human, 2000);
		human.setSelectedPlanet(selectedPlanet);
		
		Planet subPlanet3 = new Planet("Mars", human, 2000);
		neighbors = new ArrayList<Planet>();
        neighbors.add(subPlanet3);
		
		human.selectPlanet(neighbors, subPlanet3.getName());
		assertTrue(human.getSelectedPlanet().getName().equalsIgnoreCase(subPlanet3.getName()));
	}
	
	/**
	 * A test to see if one of the planets which is not available from the list of planets is selected. 
	 */
	public void testUnavailablePlanet()
	{
		Human human = new Human("CiaoBetty");
        Planet selectedPlanet = new Planet("Earth", human, 2000);
		human.setSelectedPlanet(selectedPlanet);
		
		Planet subPlanet3 = new Planet("Mars", human, 2000);
		neighbors = new ArrayList<Planet>();
        neighbors.add(subPlanet3);
		
		String planetName = "Jupiter";
        assertFalse(human.getSelectedPlanet().getName().equalsIgnoreCase(planetName));		
	}
	
	

}
